package com.example.demo.dto.user.reg;

import org.springframework.util.StringUtils;

public class URegDto {
    private Integer identity; // 0管理员 ；1教师；2学生
    private String username;
    private String password;
    private String gender;
    private Integer class_id;
    private String card_id;
    private String dorm_id;

    public Integer getIdentity() {
        return identity;
    }

    public String getDorm_id() {
        return dorm_id;
    }

    public void setDorm_id(String dorm_id) {
        this.dorm_id = dorm_id;
    }

    public void setIdentity(Integer identity) {
        this.identity = identity;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }


    public Integer getClass_id() {
        return class_id;
    }

    public void setClass_id(Integer class_id) {
        this.class_id = class_id;
    }

    public String getCard_id() {
        return card_id;
    }

    public void setCard_id(String card_id) {
        this.card_id = card_id;
    }

    // 参数校验
    public String CheckOut(){
        if(!StringUtils.hasLength(this.username)){
            return "姓名不得为空";
        }
        if(!StringUtils.hasLength(this.password)){
            return "密码不得为空";
        }
        if(this.getPassword().length() < 3 || this.getPassword().length() >12){
            return "密码长度有误";
        }
        if(!StringUtils.hasLength(this.gender)){
            return "性别不得为空";
        }
        if(!(this.getGender().equals("男") || this.getGender().equals("女"))){
            return "性别填写有误";
        }
        if(!StringUtils.hasLength(this.card_id)){
            return "身份证号不得为空";
        }
        if(this.getCard_id().length() != 18){
            return "身份证号填写有误";
        }
        // 1-以上参数是检查管理员、教师、学生都需要校验的参数
        if(this.getIdentity() == 0 || this.getIdentity() == 1){
            // 管理员、教师相关参数已检查完毕
            return "";
        }
        if(this.getClass_id() < 0){
            return "班级填写有误";
        }
        if(!StringUtils.hasLength(this.dorm_id)){
            return "宿舍号不得为空";
        }
        return "";
    }
}
